﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pay.Entity;
using System.Data.SqlClient;
using System.Data;

namespace pay.DAL
{
    public class ProductDAL
    {
        /// <summary>
        /// 根据主键得到一个Web_Product对象
        /// </summary>
        /// <param name="id">主键编号</param>
        /// <returns>Web_Product对象</returns>
        public Product GetElementById(object id)
        {
            SqlConnection con = null;
            SqlDataReader reader = null;
            try
            {
                Tools tool = new Tools();
                tool.AddSqlParameter("id", SqlDbType.Int, 4, id);
                con = new SqlConnection(DBConn.Con_Etone);
                reader = Emoney.DataAccess.SqlHelper.ExecuteReader(con, CommandType.StoredProcedure, "Web_Product_Get_ById", tool.GetSqlParameters());
                Product m = new Product();
                if (reader.Read())
                {
                    m.Id = Tools.GetInt(reader["id"]);
                    m.Productname = Tools.GetString(reader["productname"]);
                    m.Price = Tools.GetDouble(reader["price"]);
                    m.Nowprice = Tools.GetDouble(reader["nowprice"]);
                    m.Medium = Tools.GetString(reader["medium"]);
                    m.Url = Tools.GetString(reader["url"]);
                    m.Content = Tools.GetString(reader["content"]);
                    m.Issell = Tools.GetInt(reader["issell"]);
                    m.Isuse = Tools.GetInt(reader["isuse"]);
                    m.Postage = Tools.GetDouble(reader["postage"]);
                    m.Attach_largess = Tools.GetInt(reader["attach_largess"]);
                    m.Ishidden = Tools.GetString(reader["ishidden"]);
                    m.Setup_date = Tools.GetDateTime(reader["setup_date"]);
                    m.Setup_user = Tools.GetString(reader["setup_user"]);
                    m.Last_modify_date = Tools.GetDateTime(reader["last_modify_date"]);
                    m.Last_modify_user = Tools.GetString(reader["last_modify_user"]);
                }
                return m;
            }
            catch (Exception ex)
            {
                LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Web_ProductDAL.GetElementById(object id)", LogYuMin.LogStates.ERROR, ex);
          
                return null;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (con != null)
                {
                    con.Close();
                }
            }
        }
    }
}
